#include "btform.h"
#include "ui_btform.h"

#include <QList>
#include <QPropertyAnimation>

BtForm::BtForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::BtForm)
{
    ui->setupUi(this);

    ui->lineBox->hide();

    //line1的动画效果
    this->line1Animation = new QPropertyAnimation(ui->line1, "geometry", this);
    line1Animation->setDuration(1500);
    line1Animation->setKeyValueAt(0, QRect(0, 15, 2, 0));
    line1Animation->setKeyValueAt(0.5, QRect(0, 0, 2, 15));
    line1Animation->setKeyValueAt(1, QRect(0, 15, 2, 0));
    line1Animation->setLoopCount(-1);
    line1Animation->start();

    //line2的动画效果
    this->line1Animation = new QPropertyAnimation(ui->line2, "geometry", this);
    line1Animation->setDuration(1800);
    line1Animation->setKeyValueAt(0, QRect(7, 15, 2, 0));
    line1Animation->setKeyValueAt(0.5, QRect(7, 0, 2, 15));
    line1Animation->setKeyValueAt(1, QRect(7, 15, 2, 0));
    line1Animation->setLoopCount(-1);
    line1Animation->start();

    //line3的动画效果
    this->line1Animation = new QPropertyAnimation(ui->line3, "geometry", this);
    line1Animation->setDuration(1700);
    line1Animation->setKeyValueAt(0, QRect(14, 15, 2, 0));
    line1Animation->setKeyValueAt(0.5, QRect(14, 0, 2, 15));
    line1Animation->setKeyValueAt(1, QRect(14, 15, 2, 0));
    line1Animation->setLoopCount(-1);
    line1Animation->start();

    //line4的动画效果
    this->line1Animation = new QPropertyAnimation(ui->line4, "geometry", this);
    line1Animation->setDuration(1600);
    line1Animation->setKeyValueAt(0, QRect(21, 15, 2, 0));
    line1Animation->setKeyValueAt(0.5, QRect(21, 0, 2, 15));
    line1Animation->setKeyValueAt(1, QRect(21, 15, 2, 0));
    line1Animation->setLoopCount(-1);
    line1Animation->start();
}

void BtForm::setIconAndText(const QString& btIcon, const QString& btText, int pageId)
{
    ui->btIcon->setPixmap(btIcon);
    ui->btText->setText(btText);
    this->pageId = pageId;
}

void BtForm::mousePressEvent(QMouseEvent *event)
{
    (void)event;
    ui->btStyle->setStyleSheet("#btStyle { background-color: rgb(30, 206, 154)}");
    //切换页面
    emit changeIndex(pageId);
}

int BtForm::getPageId()
{
    return pageId;
}

void BtForm::setOriginalStyleSheet()
{
    ui->btStyle->setStyleSheet("#btStyle:hover {background-color: #d8d8d8;}");
}

void BtForm::hideAnimation()
{
    ui->lineBox->hide();
}

void BtForm::showAnimation()
{
    ui->lineBox->show();
}

void BtForm::highLighting()
{
    ui->btStyle->setStyleSheet("#btStyle { background-color: rgb(30, 206, 154)}");
}

BtForm::~BtForm()
{
    delete ui;
}
